﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace VisualExamEngine
{
    public partial class frmExamProperties : Form
    {
        private frmMdiChild mdi_child;

        public frmExamProperties(frmMdiChild mdi_child)
        {
            InitializeComponent();

            this.mdi_child = mdi_child;
        }

        /// <summary>
        /// DateTime: 5/9/15 11:50 PM
        /// Author: Mike Hartwig
        /// Purpose: Close this form
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnCancel_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        /// <summary>
        /// DateTime: 5/12/15 11:00 PM
        /// Author: Mike Hartwig
        /// Purpose: Show the section name form
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnNew_Click(object sender, EventArgs e)
        {
            frmSectionName sName = new frmSectionName(this, this.mdi_child);
            sName.ShowDialog();
        }

        /// <summary>
        /// DateTime: 5/12/15 11:50 PM
        /// Author: Mike Hartwig
        /// Purpose: Delete the selected section
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnDelete_Click(object sender, EventArgs e)
        {
            this.lstSections.Items.RemoveAt(this.lstSections.SelectedIndices[0]);
        }

        /// <summary>
        /// DateTime: 5/12/15 11:50 PM
        /// Author: Mike Hartwig
        /// Purpose: The listview index changed
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void tabExamProps_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (this.tabExamProps.SelectedTab.Text == "Sections")
            {
                if (this.lstSections.Items.Count <= 0)
                {
                    this.btnDelete.Enabled = false;
                    this.btnMoveDown.Enabled = false;
                    this.btnMoveUp.Enabled = false;
                    this.btnRename.Enabled = false;
                }
                else
                {
                    this.btnDelete.Enabled = true;
                    this.btnMoveDown.Enabled = true;
                    this.btnMoveUp.Enabled = true;
                    this.btnRename.Enabled = true;
                }
            }
            if (this.tabExamProps.SelectedTab.Text == "Common")
            {
                //get the exam name from the child tag
                clsExam exam = (clsExam)mdi_child.Tag;

                //set the exam title
                this.txtTitle.Text = exam.ExamTitle;
            }
        }

        /// <summary>
        /// DateTime: 5/12/15 9:30 PM
        /// Author: Mike Hartwig
        /// Purpose: Move the selected listbox item up.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnMoveUp_Click(object sender, EventArgs e)
        {
            clsUtilities.MoveItem(-1, this.lstSections);
        }

        /// <summary>
        /// DateTime: 5/12/15 9:38 PM
        /// Author: Mike Hartwig
        /// Purpose: Move the selected listbox item down.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnMoveDown_Click(object sender, EventArgs e)
        {
            clsUtilities.MoveItem(1, this.lstSections);
        }

        /// <summary>
        /// DateTime: 5/12/15 9:38 PM
        /// Author: Mike Hartwig
        /// Purpose: User selected a section. Enabled some gui items.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void lstSections_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (this.lstSections.SelectedIndex == 0)
            {
                this.btnMoveUp.Enabled = false;
            }
            else
            {
                this.btnMoveUp.Enabled = true;
            }

            if (this.lstSections.SelectedIndex == this.lstSections.Items.Count - 1)
            {
                this.btnMoveDown.Enabled = false;
            }
            else
            {
                this.btnMoveDown.Enabled = true;
            }
            
            this.btnRename.Enabled = true;
            this.btnDelete.Enabled = true;
        }

        /// <summary>
        /// DateTime: 5/14/15 9:38 PM
        /// Author: Mike Hartwig
        /// Purpose: Set exam properties
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnOK_Click(object sender, EventArgs e)
        {

            this.Close();
        }

        /// <summary>
        /// DateTime: 5/14/15 9:38 PM
        /// Author: Mike Hartwig
        /// Purpose: Form Load Event
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void frmExamProperties_Load(object sender, EventArgs e)
        {
            //get the exam name from the child tag
            clsExam exam = (clsExam)mdi_child.Tag;

            //set the exam title
            this.txtTitle.Text = exam.ExamTitle;
        }
    }
}
